<%
    def columns=tableDefine.columns
    def varDomainName=tableNameUtil.lowerCaseFirst(tableDefine.id)
    def urlPrefix=PubUtils.addStrBeforeSeparator(PubUtils.packageToPath(config.category),".")+varDomainName
    def formRuleDefineJson = customTool['formRuleDefineJson'];
%>
<template>
    <div>
        <a-modal title="修改 ${tableDefine.cnname}" v-model="modalVisible">
            <a-form ref="editForm" :form="form">
                <% columns.each{
                    def column=it;

                    if(tableModel.isNotInList('updateList',column.columnName)){
                        return ;
                    }
                %>
                <a-form-item label="${column.cnname}" :label-col="formLabelWidth" :wrapperCol="formWrapperWidth" prop="${column.dataName}">
                    <a-input v-model="formItems.${column.dataName}" :maxlength="${column.length}" :disabled="${column.getIsPK()}"
                             v-decorator="${formRuleDefineJson(column)}"
                    />
                </a-form-item>
                <%

                    }
                %>
            </a-form>

            <div slot="footer">
                <a-button key="back" :loading="loading" @click="show(false)">Cancel</a-button>
                <a-button key="submit" type="primary" :loading="loading" @click="submitForm">Submit</a-button>
            </div>
        </a-modal>
    </div>
</template>
<script>
    var _ = require('underscore')

    let formItems = {
<%
		 	def listSize=tableModel.listSize('updateList');
		 	int i=0;
			columns.each{
			  def column=it;
			  if(tableModel.isNotInList('addList',column.columnName)){
				return ;
			  }
		    print """\t\t${column.dataName}: null"""
		 	i++;
			if(i<listSize) println ',';

		}
		%>
    };

    export default {
        data() {
            return {
                loading: false,
                modalVisible: false,
                formItems: _.clone(formItems),
                form: this.\$form.createForm(this),
                formLabelWidth: { lg: { span: 5 }, sm: { span: 7 } },
                formWrapperWidth: { lg: { span: 16 }, sm: { span: 17 } }
            }
        },
        methods: {
            show(isShow) {
                this.modalVisible = isShow
            },
            submitForm (e) {
                e.preventDefault();
                const _this = this
                this.form.validateFields((err, values) => {
                    if (!err) {
                        _this.loading = true
                        const promise = new Promise(function(resolve, reject) {
                            // remote ajax request ,need implement
                            setTimeout(function() {
                                _this.loading = false
                                resolve({ 'success': true })
                            }, 1000)
                        })
                        promise.then(function(data) {
                            _this.\$message.success('新增成功！')
                            _this.show(false)
                            _this.\$emit('refreshList')
                        }).catch(function() {
                            _this.\$message.error('修改失败！')
                        })
                    } else {
                        _this.\$message.warning('参数有误')
                        return false
                    }
                })
            },
            editItem(item){
                this.formItems = item;
                this.show(true);
            }
        }
    }
</script>
